package com.lagou.demo.controller;

import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 阶段一模块三作业
 * @author zyh
 * @since jdk 11
 * @date 2021-07-07 18:21:11
 */
@LagouController
@LagouRequestMapping("/homework")
public class HomeWorkController {

    @LagouRequestMapping("/getUserNameLength")
    @Security(name = "getUserNameLength", value = {"wangyi", "lier", "zhangsan"})
    public void getUserNameLength(HttpServletRequest request, HttpServletResponse response, String userName) throws IOException {
        response.getWriter().write("The length of " + userName + "'s user name is " + userName.length());
    }

    @LagouRequestMapping("/getUserPhone")
    @Security(name = "getUserPhone", value = {"zhaosi", "liuqi", "cuijiu"})
    public void getUserPhone(HttpServletRequest request, HttpServletResponse response, String userName) throws IOException {
        String mobile;
        switch (userName) {
            case "zhaosi": mobile = "13824562277"; break;
            case "liuqi": mobile = "13824562434"; break;
            case "cuijiu": mobile = "13824569876"; break;
            default: mobile = "13824562233";
        }
        response.getWriter().write(userName + "'s mobile phone number is " + mobile);
    }
}
